{% extends 'base.html' %}

{% block title %}系统状态 | Tiny QA{% endblock %}

{% block content %}
<div class="container mt-5">
    <h2 class="mb-4">
        <i class="bi bi-activity text-primary me-2"></i>系统状态
    </h2>
    
    <div id="status-info">
        <div class="text-center">
            <div class="spinner-border text-primary" role="status">
                <span class="visually-hidden">加载中...</span>
            </div>
            <p class="mt-2">正在加载系统状态...</p>
        </div>
    </div>
</div>

<script>
// 加载系统状态
async function loadStatus() {
    const statusDiv = document.getElementById('status-info');
    try {
        const resp = await fetch('/api/status');
        const data = await resp.json();
        
        let html = `
            <div class="row">
                <div class="col-md-6">
                    <div class="card mb-3">
                        <div class="card-header bg-primary text-white">
                            <i class="bi bi-file-earmark-text me-2"></i>文档统计
                        </div>
                        <div class="card-body">
                            <ul class="list-group list-group-flush">
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-files me-2"></i>总文档数</span>
                                    <span class="badge bg-primary rounded-pill">${data.total_documents}</span>
                                </li>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-check-circle me-2"></i>已处理文档</span>
                                    <span class="badge bg-success rounded-pill">${data.processed_documents}</span>
                                </li>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-clock me-2"></i>待处理文档</span>
                                    <span class="badge bg-warning rounded-pill">${data.total_documents - data.processed_documents}</span>
                                </li>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-puzzle me-2"></i>文本块总数</span>
                                    <span class="badge bg-info rounded-pill">${data.total_chunks}</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-6">
                    <div class="card mb-3">
                        <div class="card-header bg-success text-white">
                            <i class="bi bi-robot me-2"></i>AI服务状态
                        </div>
                        <div class="card-body">
                            <ul class="list-group list-group-flush">
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-activity me-2"></i>服务状态</span>
                                    <span class="badge ${data.ai_service_status === '正常' ? 'bg-success' : 'bg-danger'} rounded-pill">
                                        ${data.ai_service_status}
                                    </span>
                                </li>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-cpu me-2"></i>当前模型</span>
                                    <span class="badge bg-secondary rounded-pill">${data.current_model}</span>
                                </li>
                                <li class="list-group-item d-flex justify-content-between align-items-center">
                                    <span><i class="bi bi-percent me-2"></i>处理进度</span>
                                    <span class="badge bg-info rounded-pill">${data.processing_rate}</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header bg-info text-white">
                            <i class="bi bi-info-circle me-2"></i>系统信息
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="text-center">
                                        <i class="bi bi-activity text-primary" style="font-size: 2rem;"></i>
                                        <h5 class="mt-2">系统性能</h5>
                                        <p class="text-muted">运行正常</p>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="text-center">
                                        <i class="bi bi-files text-success" style="font-size: 2rem;"></i>
                                        <h5 class="mt-2">数据存储</h5>
                                        <p class="text-muted">${data.total_chunks} 个向量</p>
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="text-center">
                                        <i class="bi bi-gear text-warning" style="font-size: 2rem;"></i>
                                        <h5 class="mt-2">配置状态</h5>
                                        <p class="text-muted">已配置</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        `;
        
        statusDiv.innerHTML = html;
    } catch (err) {
        statusDiv.innerHTML = `
            <div class="alert alert-danger">
                <i class="bi bi-exclamation-triangle me-2"></i>
                <strong>加载失败</strong> - 无法获取系统状态信息
            </div>
        `;
    }
}

// 页面加载时执行
window.onload = loadStatus;

// 每30秒自动刷新一次
setInterval(loadStatus, 30000);
</script>
{% endblock %} 